

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.dtype &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.dtype_to_nptype" href="mindspore.dtype_to_nptype.html" />
    <link rel="prev" title="mindspore.ParameterTuple" href="mindspore.ParameterTuple.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.html">mindspore</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id1">张量</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id2">参数</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.html#id3">数据类型</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.dtype</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dtype_to_nptype.html">mindspore.dtype_to_nptype</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.issubclass_.html">mindspore.issubclass_</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dtype_to_pytype.html">mindspore.dtype_to_pytype</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.pytype_to_dtype.html">mindspore.pytype_to_dtype</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.get_py_obj_dtype.html">mindspore.get_py_obj_dtype</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id4">随机种子</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id5">模型</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id6">数据处理工具</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id7">混合精度管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id8">序列化</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id9">即时编译</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id10">日志</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id11">自动混合精度</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id12">安装验证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id13">调试</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.html#id14">内存回收</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.html">mindspore</a> &raquo;</li>
        
      <li>mindspore.dtype</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/mindspore/mindspore.dtype.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-dtype">
<h1>mindspore.dtype<a class="headerlink" href="#mindspore-dtype" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.dtype">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.</code><code class="sig-name descname">dtype</code><a class="headerlink" href="#mindspore.dtype" title="Permalink to this definition">¶</a></dt>
<dd><p>创建一个MindSpore数据类型的对象。</p>
<p><cite>dtype</cite> 的实际路径为 <cite>/mindspore/common/dtype.py</cite> ，运行以下命令导入环境：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">dtype</span> <span class="k">as</span> <span class="n">mstype</span>
</pre></div>
</div>
<ul>
<li><p><strong>数值型</strong></p>
<p>目前，MindSpore支持 <code class="docutils literal notranslate"><span class="pre">Int</span></code>，<code class="docutils literal notranslate"><span class="pre">Uint</span></code> 和 <code class="docutils literal notranslate"><span class="pre">Float</span></code> 数据类型，详情请参照以下表格。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 61%" />
<col style="width: 39%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>定义</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.int8</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.byte</span></code></p></td>
<td><p>8位整型数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.int16</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.short</span></code></p></td>
<td><p>16位整型数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.int32</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.intc</span></code></p></td>
<td><p>32位整型数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.int64</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.intp</span></code></p></td>
<td><p>64位整型数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.uint8</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.ubyte</span></code></p></td>
<td><p>无符号8位整型数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.uint16</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.ushort</span></code></p></td>
<td><p>无符号16位整型数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.uint32</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.uintc</span></code></p></td>
<td><p>无符号32位整型数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.uint64</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.uintp</span></code></p></td>
<td><p>无符号64位整型数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.float16</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.half</span></code></p></td>
<td><p>16位浮点数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.float32</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.single</span></code></p></td>
<td><p>32位浮点数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.float64</span></code> ,  <code class="docutils literal notranslate"><span class="pre">mindspore.double</span></code></p></td>
<td><p>64位浮点数</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.complex64</span></code></p></td>
<td><p>64位复数</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mindspore.complex128</span></code></p></td>
<td><p>128位复数</p></td>
</tr>
</tbody>
</table>
</li>
<li><p><strong>其他类型</strong></p>
<p>除数值型以外的其他数据类型，请参照以下表格。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 15%" />
<col style="width: 85%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>类型</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Tensor</span></code></p></td>
<td><p>MindSpore中的张量类型。数据格式采用NCHW。详情请参考 <a class="reference external" href="https://www.gitee.com/mindspore/mindspore/blob/master/mindspore/python/mindspore/common/tensor.py">tensor</a> 。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">bool_</span></code></p></td>
<td><p>布尔型，值为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">False</span></code> 。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">int_</span></code></p></td>
<td><p>整数标量。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">uint</span></code></p></td>
<td><p>无符号整数标量。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">float_</span></code></p></td>
<td><p>浮点标量。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">complex</span></code></p></td>
<td><p>复数标量。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">number</span></code></p></td>
<td><p>数值型, 包括 <code class="docutils literal notranslate"><span class="pre">int_</span></code> , <code class="docutils literal notranslate"><span class="pre">uint</span></code> , <code class="docutils literal notranslate"><span class="pre">float_</span></code> , <code class="docutils literal notranslate"><span class="pre">complex</span></code> 和 <code class="docutils literal notranslate"><span class="pre">bool_</span></code>。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">list_</span></code></p></td>
<td><p>由 <code class="docutils literal notranslate"><span class="pre">tensor</span></code> 构造的列表，例如 <code class="docutils literal notranslate"><span class="pre">List[T0,T1,...,Tn]</span></code> ，其中元素 <code class="docutils literal notranslate"><span class="pre">Ti</span></code> 可以是不同的类型。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">tuple_</span></code></p></td>
<td><p>由 <code class="docutils literal notranslate"><span class="pre">tensor</span></code> 构造的元组，例如 <code class="docutils literal notranslate"><span class="pre">Tuple[T0,T1,...,Tn]</span></code> ，其中元素 <code class="docutils literal notranslate"><span class="pre">Ti</span></code> 可以是不同的类型。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">function</span></code></p></td>
<td><p>函数类型。 两种返回方式，当function不是None时，直接返回function，另一种当function为None时返回function(参数: List[T0,T1,…,Tn], 返回值: T)。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">type_type</span></code></p></td>
<td><p>类型的类型定义。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">type_none</span></code></p></td>
<td><p>没有匹配的返回类型，对应 Python 中的 <code class="docutils literal notranslate"><span class="pre">type(None)</span></code>。</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">symbolic_key</span></code></p></td>
<td><p>在 <code class="docutils literal notranslate"><span class="pre">env_type</span></code> 中用作变量的键的变量的值。</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">env_type</span></code></p></td>
<td><p>用于存储函数的自由变量的梯度，其中键是自由变量节点的 <cite>symbolic_key</cite> ，值是梯度。</p></td>
</tr>
</tbody>
</table>
</li>
<li><p><strong>树形拓扑</strong></p>
<p>以上定义的数据类型遵从如下的树形拓扑结构：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>└─────── number
    │   ├─── bool_
    │   ├─── int_
    │   │   ├─── int8, byte
    │   │   ├─── int16, short
    │   │   ├─── int32, intc
    │   │   └─── int64, intp
    │   ├─── uint
    │   │   ├─── uint8, ubyte
    │   │   ├─── uint16, ushort
    │   │   ├─── uint32, uintc
    │   │   └─── uint64, uintp
    │   ├─── float_
    │   │    ├─── float16
    │   │    ├─── float32
    │   │    └─── float64
    │   └─── complex
    │       ├─── complex64
    │       └─── complex128
    ├─── tensor
    │   ├─── Array[Float32]
    │   └─── ...
    ├─── list_
    │   ├─── List[Int32,Float32]
    │   └─── ...
    ├─── tuple_
    │   ├─── Tuple[Int32,Float32]
    │   └─── ...
    ├─── function
    │   ├─── Func
    │   ├─── Func[(Int32, Float32), Int32]
    │   └─── ...
    ├─── type_type
    ├─── type_none
    ├─── symbolic_key
    └─── env_type
</pre></div>
</div>
</li>
</ul>
</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.dtype_to_nptype.html" class="btn btn-neutral float-right" title="mindspore.dtype_to_nptype" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.ParameterTuple.html" class="btn btn-neutral float-left" title="mindspore.ParameterTuple" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>